typedef BoolCallback = bool Function();
typedef ConvertCallback<T> = T? Function(dynamic item);

/// A service class with common shared methods.
class SharedUtil {
  /// Checks if the input [str] is null or empty string.
  static bool checkNullOrEmpty(String? str) {
    return str == null || str.trim().isEmpty;
  }

  /// Tries to convert input [item] by [convertCallback] if [item] is not null.
  /// Otherwize null is returned.
  static T? tryToConvert<T>(dynamic item, ConvertCallback convertCallback,
      {dynamic defaultValue}) {
    if (item == null || checkNullOrEmpty(item?.toString())) {
      return defaultValue;
    }

    return convertCallback(item);
  }
}
